<?php

include_once("./resource/SDK/CCPRestSmsSDK.php");
require_once ('./resource/SDK/XingeApp.php');
include_once("./resource/SDK/bankele1.php");
class Involved_LogModel extends BaseModel
{

    protected $table = 'log';

    /**
     * 管理员列表
     * @return mixed
     */
    public function LogService()
    {

        return DB::table($this->table)
            ->select('log_id', 'operator', 'content', 'type', 'log.created', 'name')
            ->join('admin', 'admin.id', '=', 'log.operator')
            ->get();
    }

    /**
     * 发送短信验证
     * @param $to
     * @param $datas
     * @param $tempId
     * @return int
     */
    function sendTemplateSMS($to, $datas, $tempId)
    {

        // 初始化REST SDK
        global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;

        $accountSid = '8a48b551544cd73f0154893f6f383aaf';
        $accountToken = 'c8a7e905a48c4ceab3613ef27bae589d';
        $appId = '8a216da8555d110e01555d3ca0d201ef';
        $serverIP = 'app.cloopen.com';
        $serverPort = '8883';
        $softVersion = '2013-12-26';

        $rest = new REST($serverIP, $serverPort, $softVersion);
        $rest->setAccount($accountSid, $accountToken);
        $rest->setAppId($appId);
        // 发送模板短信
        //echo "Sending TemplateSMS to $to <br/>";
        $result = $rest->sendTemplateSMS($to, $datas, $tempId);
        if ($result == NULL) {
            echo "result error!";
            die;
        }
        if ($result->statusCode != 0) {
//            echo "error code :" . $result->statusCode . "<br>";
//            echo "error msg :" . $result->statusMsg . "<br>";
            return $result->statusCode;
            //TODO 添加错误处理逻辑
        } else {
//            echo "Sendind TemplateSMS success!<br/>";
//            // 获取返回信息
//            $smsmessage = $result->TemplateSMS;
//            echo "dateCreated:".$smsmessage->dateCreated."<br/>";
//            echo "smsMessageSid:".$smsmessage->smsMessageSid."<br/>";
//            //TODO 添加成功处理逻辑
            return 10000;
        }
    }

    function BankAuth($paramObj,$mobile)
    {
        $bankeleobj = new bankele();
//        $token = "SbdzQR2ja0d7FkxdgqjHavbcTmUQapm8iHLWIVf4XFo=";
        $result=$bankeleobj->auth($paramObj->real_name,$paramObj->id_card,$paramObj->bank_num,$paramObj->bank_code,$mobile,$paramObj->bank_token);
        return $result;

    }

    function BankConfirm($paramObj,$mobile){
        $bankeleobj = new bankele();
//        $token = "SbdzQR2ja0d7FkxdgqjHavbcTmUQapm8iHLWIVf4XFo=";
        $result=$bankeleobj->confirm($paramObj->real_name,$paramObj->id_card,$paramObj->bank_num,$paramObj->bank_code,$mobile,$paramObj->bank_token,$paramObj->verify);
        return $result;
    }

}